/*
 *简单小路由案例
 * /student/123456
 * /teacher/123
 * 
 * */

var http = require("http");
http.createServer(function(req, res) {
	res.writeHead(200,{"content-type":"text/html;charset=UTF8"});
	var url = req.url;
	var str = url.substr(0,9);
	var msg = '';
    if(str == '/student/'){
    	var sId = url.substr(9);
    	if(/^\d{6}$/.test(sId)){
    		msg = '查询的学生id是：'+sId;
    	}else{
    		msg = "查询的位数不对";
    	}
    }else if(str == '/teacher/'){
    	var tId = url.substr(9);
    	if(/^\d{3}$/.test(tId)){
    		msg = '查询的教师id是：'+tId;
    	}else{
    		msg = "查询的位数不对";
    	}
    }else{
    	msg = "请检查url";
    }
    res.end(msg);
}).listen(3000,"127.0.0.1");
